package com.backend.apartment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.backend.common.annotation.Log;
import com.backend.common.core.controller.BaseController;
import com.backend.common.core.domain.AjaxResult;
import com.backend.common.enums.BusinessType;
import com.backend.apartment.domain.Apartment;
import com.backend.apartment.service.IApartmentService;
import com.backend.common.utils.poi.ExcelUtil;
import com.backend.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/apartment/apartment")
public class ApartmentController extends BaseController {
    @Autowired
    private IApartmentService apartmentService;
    @PreAuthorize("@ss.hasPermi('apartment:apartment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Apartment apartment)
    {
        startPage();
        List<Apartment> list = apartmentService.selectApartmentList(apartment);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('apartment:apartment:export')")
    @Log(title = "房间管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Apartment apartment)
    {
        List<Apartment> list = apartmentService.selectApartmentList(apartment);
        ExcelUtil<Apartment> util = new ExcelUtil<Apartment>(Apartment.class);
        util.exportExcel(response, list, "房间管理数据");
    }
    @PreAuthorize("@ss.hasPermi('apartment:apartment:query')")
    @GetMapping(value = "/{apartmentId}")
    public AjaxResult getInfo(@PathVariable("apartmentId") Long apartmentId)
    {
        return success(apartmentService.selectApartmentByApartmentId(apartmentId));
    }
    @PreAuthorize("@ss.hasPermi('apartment:apartment:add')")
    @Log(title = "房间管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Apartment apartment)
    {
        return toAjax(apartmentService.insertApartment(apartment));
    }
    @PreAuthorize("@ss.hasPermi('apartment:apartment:edit')")
    @Log(title = "房间管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Apartment apartment)
    {
        return toAjax(apartmentService.updateApartment(apartment));
    }
    @PreAuthorize("@ss.hasPermi('apartment:apartment:remove')")
    @Log(title = "房间管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{apartmentIds}")
    public AjaxResult remove(@PathVariable Long[] apartmentIds)
    {
        return toAjax(apartmentService.deleteApartmentByApartmentIds(apartmentIds));
    }
}
